//package com.lsq.tucao.login.shiro.config;
//
//import com.lsq.tucao.login.shiro.realm.CustomRealm;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
//import org.apache.shiro.mgt.DefaultSubjectDAO;
//import org.apache.shiro.mgt.SecurityManager;
//import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
//import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
//import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
//import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * shiro的配置类
// */
//@Slf4j
//@Configuration
//public class ShiroConfig {
//
//    @Bean
//    public CustomRealm shiroRealm() {
//        CustomRealm customRealm = new CustomRealm();
//        return customRealm;
//    }
//
//    @Bean
//    public SecurityManager securityManager() {
//        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
//        securityManager.setRealm(shiroRealm());
//
//        /*
//         * 关闭shiro自带的session，详情见文档
//         * http://shiro.apache.org/session-management.html#SessionManagement-StatelessApplications%28Sessionless%29
//         */
////        DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
////        DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();
////        defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
////        subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator);
////        securityManager.setSubjectDAO(subjectDAO);
//
//        return securityManager;
//    }
//
//    /**
//     * 拦截
//     * @param securityManager
//     * @return
//     */
//    @Bean
//    public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
//        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
//        shiroFilterFactoryBean.setSecurityManager(securityManager);
//
////        //登录
////        //拦截未登录用户的请求 转发到登陆界面
////        shiroFilterFactoryBean.setLoginUrl("https://hao.360.com/?src=lm&ls=n2b2986f18b");
////        //登陆成功进入首页
////        log.debug("登陆成功 进入首页");
////        shiroFilterFactoryBean.setSuccessUrl("https://www.baidu.com");
////        //未授权
////        shiroFilterFactoryBean.setUnauthorizedUrl("/403");
//
//        //自定义拦截请求
//        Map<String, String> map = new HashMap<>();
//        map.put("/druid/**", "anon");
//        map.put("/login", "anon");
//        map.put("/logout", "anon");
//        map.put("/register", "anon");
//        map.put("/**", "authc");
//
////        //自定义过滤器链
////        Map<String, Filter> filters = new HashMap<>();
////        //指定拦截器处理
////        filters.put("authc", new JwtInterceptor());
////        filters.put("jwt", new JwtInterceptor());
////        shiroFilterFactoryBean.setFilters(filters);
//
////        map.put("/**","jwt");
//
//        shiroFilterFactoryBean.setFilterChainDefinitionMap(map);
//
//        return shiroFilterFactoryBean;
//    }
//
//    /**
//     * 交给spring容器管理,开启AOP注解支持
//     * @param securityManager
//     * @return
//     */
//    @Bean
//    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
//        AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
//        authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
//        return authorizationAttributeSourceAdvisor;
//    }
//
//    @Bean
//    @ConditionalOnMissingBean
//    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
//        DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
//        defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
//        return defaultAdvisorAutoProxyCreator;
//    }
//
//}
